$(function() { $("#tabs").tabs();  });
  
$(document).ready(function() { 
    
    hs.graphicsDir = url_base+'app/admin/view/temp/default/layout/css/highslide/graphics/';
    hs.align = 'center';
    hs.closeText = '<img border="0" src="'+url_base+'app/admin/view/temp/default/layout/css/highslide/graphics/close_X.png" />';
    hs.creditsText = 'this.a.title';
    hs.outlineType = 'rounded-white';
    hs.showCredits = false;
    hs.wrapperClassName = 'draggable-header';
    hs.cacheAjax = false;
    hs.dimmingOpacity = 0.7;
    hs.onDimmerClick = function() { return false;}
    
     
    $('#btn-submit').click(function() {  
    
      var hasError = false;
      var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
    
      var emailaddressVal = $("#Email").val();
      if(emailaddressVal == '') {
          $(".error").show().text(_['error_emal_empty']);
          hasError = true;
      }
    
      else if(!emailReg.test(emailaddressVal)) {
          $(".error").show().text(_['error_emal_no_format']);
          hasError = true;
      }
    
      if(hasError == true) { return false; }
    
    });
    
    $('input:checkbox[name="delId[]"]').click(function() { 
    
    if( $(this).attr("checked")== "checked"){
        
        $('.but_tool').removeClass('butx').addClass('but_login').attr("disabled",false);
        
    }else{
        
        if(getValCb().length>0)
        {               
            $('.but_tool').removeClass('butx').addClass('but_login').attr("disabled",false);
        }else{
            $('.but_tool').removeClass('but_login').addClass('butx').attr("disabled",true);   
        }
        
        
    }
    
    
    
    });
 });

function checkAll()
{
    if(getValCb().length>0){
        
        $('.but_tool').removeClass('but_login').addClass('butx').attr("disabled",true);
        $('input:checkbox[name="all"]').removeAttr("checked");
		$('input:checkbox[name="delId[]"]').removeAttr("checked");
        
	}else{
	    
        $('.but_tool').removeClass('butx').addClass('but_login').attr("disabled",false);
	    $('input:checkbox[name="all"]').attr("checked","checked");
		$('input:checkbox[name="delId[]"]').attr("checked","checked");
    }
	
}

function getValCb()
{
	var delId = [];
	$('input:checkbox[name="delId[]"]:checked')
	.each( function(index) { 
		delId.push($(this).val());
	});
	
	return delId;
}

function setOrderAjax(ID,act)
{
    var url = _seokey[0]+"/ajax/"+act+"/"+ID+"/";
    $.ajax({ 
        type    : "GET",
        url     : url_base+url, 
        cache   : false

     });
}

function processChecked(active, com)
{
    var StrID = getValCb();
	switch (active)
	{
		case 'show':
			var strData = _seokey[0]+'/'+com+"/ajax/"+active+"/"+StrID;
			var sms = _['showx'];
			var smsError=_['error_show'];
			var errorNotOK = _['error_ok_show'];
            var status = _['show'];
            var classx = 're';
        break;
		
		case 'hide':
			var strData = _seokey[0]+'/'+com+"/ajax/"+active+"/"+StrID;
			var sms =  _['hidex'];
			var smsError=_['error_hide'];
			var errorNotOK = _['error_ok_hide'];
            var status = _['hide'];
            var classx = 'add';
        break;
        
        case 'delete':
			var strData = _seokey[0]+'/'+com+"/ajax/"+active+"/"+StrID;
			var sms =  _['delete'];
			var smsError=_['error_delete'];
			var errorNotOK = _['error_ok_delete'];
            var deletex = 'ok';
		break;
        
	}
	
	if(StrID!=""){
		var smsCheck = confirm(sms);
		if(smsCheck==true){
			$.ajax({ 
			   type: "POST", 
			   url: url_base+""+strData, 
			   cache: false,
			   dataType: "html",
			   success: function(DataHtml){ 
			   	 if(DataHtml=='ok')
                 {
				 	for(x in StrID)
                    {
                            if(deletex)
                            {
                                $('.tr'+StrID[x]).remove();                                
                            }
                            else{
                                $('.status'+StrID[x]).text(status);
                                if(classx=='add'){
                                    $('.tr'+StrID[x]).addClass('class_false');
                                    $('.tr'+StrID[x]).removeClass('class_true');
                                }else{
                                    $('.tr'+StrID[x]).removeClass('class_false');
                                    $('.tr'+StrID[x]).addClass('class_true');
                                }
                                
                            }
                        
                        
                    }
                    if(active == 'delete'){
                        location.reload(true);    
                    }
				 }
                 else{
                    alert(errorNotOK);                   
                    
				 }
				 
			   } 
			});
		}
	
	}else{
		alert(smsError);
	
	}
}

$(document).ready(function(){
    $('#seo_key').change( function() {    
        var url = url_base + 'admin/permission/ajax/getaction';
        var id_seokey = $("#seo_key option:selected").attr('title');       
        $.post(url,{
            id_seokey:id_seokey
        },function(data){
            if(data != 'no-data'){
                $('#action').html(data);
            }else{
                $('#action').html('<select name="action" class="field select small" tabindex="3" id="action">'+ '<option value="">Select Seo Key</option>'+'</select>');
            }
        });
   });
   
   $('#app').change( function() {    
        var url = url_base + 'admin/permission/ajax/getseokey';
        var app = $("#app option:selected").attr('value');       
        $.post(url,{
            app:app
        },function(data){
            if(data != 'no-data'){
                $('#seo_key').html(data);
            }else{
                $('#seo_key').html('<select name="seo_key" class="field select small" tabindex="3" id="seo_key">'+ '<option value="">Select Seo Key</option>'+'</select>');
            }
            $('#action').html('<select name="action" class="field select small" tabindex="3" id="action">'+ '<option value="">Select Seo Key</option>'+'</select>');
        });
   });
   
});


function change_filter (){
  
        var cid = $(".filter option:selected").attr('value');    
        $.ajax({ 
            type: "POST", 
            url: url_base + 'index.php', 
            data: 'route=admin/permission/ajax/filter/'+cid,
            cache: false,
            dataType: "html",
            success: function(DataHtml){ 
                $(".content").html(DataHtml);
            }     
       }); 
       
}





